package prometheus

import (
	"github.com/prometheus/client_golang/prometheus"
	"github.com/tluo-github/super-runner/common"
	"runtime"
)

/**
	VersionCollector 提供Super Runner 版本及构建相关数据收集器
*/

type VersionCollector struct {
	VersionGauge *prometheus.GaugeVec
}

func (vc *VersionCollector) Describe(ch chan<- *prometheus.Desc) {
	vc.VersionGauge.Describe(ch)
}
func (vc *VersionCollector) Collect(ch chan<- prometheus.Metric) {

	vc.VersionGauge.Collect(ch)
}

func NewVersionCollector() *VersionCollector {

	labels := map[string]string{
		"go_version":   runtime.Version(),
		"os":           runtime.GOOS,
		"architecture": runtime.GOARCH,
		"super_runner_version": common.VERSION,
	}
	labelNames := make([]string, 0, len(labels))
	for n := range labels {
		labelNames = append(labelNames, n)
	}

	versionInfo := prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name:    "super_runner_version_info",
			Help:    "super runner 版本信息",
		},
		labelNames,
	)
	versionInfo.With(labels).Set(1)

	return &VersionCollector{
			VersionGauge: versionInfo,
	}
}

